package com.kingeid.hlj.test.mvp.model;

import android.app.Application;

import com.google.gson.Gson;
import com.jess.arms.integration.IRepositoryManager;
import com.jess.arms.mvp.BaseModel;

import com.jess.arms.di.scope.ActivityScope;

import javax.inject.Inject;

import com.kingeid.hlj.test.mvp.contract.LoginContract;
import com.kingeid.hlj.test.mvp.model.api.service.UserService;
import com.kingeid.hlj.test.mvp.model.api.service.params.LoginParams;
import com.kingeid.hlj.test.mvp.model.api.service.params.PhoneCode;
import com.kingeid.hlj.test.mvp.model.entity.BaseResponse;
import com.kingeid.hlj.test.mvp.model.entity.User;

import io.reactivex.Observable;


/**
 * ================================================
 * Description:
 * <p>
 * Created by huanglj on 11/29/2019 15:40
 * ================================================
 */
@ActivityScope
public class LoginModel extends BaseModel implements LoginContract.Model {

    @Inject
    Gson mGson;
    @Inject
    Application mApplication;

    @Inject
    public LoginModel(IRepositoryManager repositoryManager) {
        super(repositoryManager);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        this.mGson = null;
        this.mApplication = null;
    }

    @Override
    public Observable<BaseResponse<String>> login(String account, String pwd) {
        LoginParams params = new LoginParams();
        params.setPhone(account);
        params.setPwd(pwd);
        return mRepositoryManager.obtainRetrofitService(UserService.class).login(params);
    }

    @Override
    public Observable<BaseResponse> getCode(String phone) {
        PhoneCode params = new PhoneCode();
        params.setPhone(phone);
        return mRepositoryManager.obtainRetrofitService(UserService.class).getCode(params);
    }
}